package fgin

import (
	"github.com/opentracing/opentracing-go"
	"github.com/uber/jaeger-client-go/config"
)

// jaeger 初始化
func initJaeger() {
	if (fginConfig.Jaeger == Jaeger{}) {
		return
	}
	var cfg *config.Configuration
	switch {
	case fginConfig.Jaeger.Address != "":
		cfg = &config.Configuration{
			ServiceName: fginConfig.ServiceName,
			Sampler: &config.SamplerConfig{
				Type:  "const",
				Param: 1,
			},
			Reporter: &config.ReporterConfig{
				LogSpans:           true,
				LocalAgentHostPort: fginConfig.Jaeger.Address,
			},
		}
	case fginConfig.Jaeger.AddressHTTP != "":
		cfg = &config.Configuration{
			ServiceName: fginConfig.ServiceName,
			Sampler: &config.SamplerConfig{
				Type:  "const",
				Param: 1,
			},
			Reporter: &config.ReporterConfig{
				LogSpans:          true,
				CollectorEndpoint: fginConfig.Jaeger.AddressHTTP,
			},
		}
	default:
		logSuger.Error("jaeger 配置不全")
		return
	}
	tracer, _, err := cfg.NewTracer()
	// 设置全局tracer
	opentracing.SetGlobalTracer(tracer)
	if err != nil {
		// 处理错误
		logSuger.Error(err)
		return
	}
}
